package pers.course.exam;

import java.util.*;

public class Fruits {
    public static void main(String[] args) {
        Map<String, Integer> s = new HashMap<>();
        int minPrice = 0, maxPrice = 0;
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        in.nextLine();
        for (int i = 0; i < m; i++) {
            String fruit = in.nextLine();
            if (s.containsKey(fruit)) {
                int temp = s.get(fruit);
                s.put(fruit, temp + 1);
            } else {
                s.put(fruit, 1);
            }
        }
        Set<Map.Entry<String, Integer>> set = s.entrySet();
        int index = 0;
        int[] b = new int[set.size()];
        for (Map.Entry<String, Integer> ss : set) {
            b[index] = ss.getValue();
            index++;
        }
        Arrays.sort(b);
        for (int i = 0; i < b.length; i++) {
            minPrice += b[b.length - 1 - i] * a[i];
            maxPrice += b[b.length - 1 - i] * a[n - i - 1];
        }
        System.out.println(minPrice + " " + maxPrice);
    }
}
